package cn.gwm.flink.streaming.strategy.termal;

import cn.gwm.flink.streaming.constant.TermalRunawayTypeEnum;
import cn.gwm.flink.streaming.constant.VehiclePowerType;
import org.apache.flink.api.java.tuple.Tuple3;
import org.apache.flink.api.java.tuple.Tuple4;

import java.util.HashMap;
import java.util.Map;

/**
 * 热失控策略工厂
 * @author GW00283474
 */
public class TermalStrategyFactory {

    private static final Map<String,Tuple4<String,TermalStrategy,Boolean,TermalStrategy>> map =new HashMap<>(0);
    static {
        map.put(TermalRunawayTypeEnum.TEMPERATURE.getKey(),new Tuple4(TermalRunawayTypeEnum.TEMPERATURE.getKey(),new TermalTemperatureEvStrategy(),true,new TermalTemperaturePhevStrategy()));
        map.put(TermalRunawayTypeEnum.VOLTAGE.getKey(),new Tuple4(TermalRunawayTypeEnum.VOLTAGE.getKey(),new TermalVoltageEvStrategy(),true,new TermalVoltagePhevStrategy()));
        map.put(TermalRunawayTypeEnum.TEMPERATUREDIFFERENCE.getKey(),new Tuple4(TermalRunawayTypeEnum.TEMPERATUREDIFFERENCE.getKey(),new TermalTemperatureDifferenceEvStrategy(),true,new TermalTemperatureDifferencePhevStrategy()));
        map.put(TermalRunawayTypeEnum.TEMPERATURERISE.getKey(),new Tuple4(TermalRunawayTypeEnum.TEMPERATURERISE.getKey(), new TermalTemperatureRiseEvStrategy(),false,new TermalTemperatureRisePhevStrategy()));
        map.put(TermalRunawayTypeEnum.VOLTAGEVARIATION.getKey(),new Tuple4(TermalRunawayTypeEnum.VOLTAGEVARIATION.getKey(),new TermalVoltageVariationEvStrategy(),false,new TermalVoltageVariationPhevStrategy()));
    }

    /**
     * 工厂生产策略实例
     * @param key 策略key
     * @param hasCycle 策略是否有生命周期
     * @return
     */
    public static TermalStrategy getTermalStrategy(String key, boolean hasCycle, VehiclePowerType vehiclePowerType){
        Tuple4<String, TermalStrategy, Boolean,TermalStrategy> tuple4 = map.get(key);
        if(hasCycle==tuple4.f2.booleanValue()){
            if(VehiclePowerType.EV.equals(vehiclePowerType)) {
                return tuple4.f1;
            }else if(VehiclePowerType.PHEV.equals(vehiclePowerType)){
                return tuple4.f3;
            }

        }
        return null;
    }
}
